//
//  MenuView.m
//  MKUITestApp
//
//  Created by 苏尚进 on 2020/8/24.
//  Copyright © 2020 moon. All rights reserved.
//

#import "MenuView.h"

@implementation MenuView
- (id)initWithFrame:(CGRect)frame{
    if (self=[super initWithFrame:frame]) {
        self.iconImageView = [[UIImageView alloc] init];
        self.iconImageView.contentMode = UIViewContentModeScaleAspectFit;
        MKUILayoutConstraintItemWrapper *w1 = [MKUILayoutConstraintItemWrapper wrapItem:self.iconImageView fixedSize:CGSizeMake(30, 30)];
        [self addSubview:self.iconImageView];
        //
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.font = [UIFont systemFontOfSize:14];
        self.titleLabel.numberOfLines = 0;
        [self addSubview:self.titleLabel];
        //
        self.flowlayout = [[MKUIFlowLayoutConstraint alloc] initWithItems:@[w1,self.titleLabel] constraintParam:(MKUIFlowLayoutConstraintParam_H_C_L) contentInsets:UIEdgeInsetsMake(10, 20, 10, 20) interitemSpacing:10];
    }
    return self;
}
- (void)setMenu:(Menu *)menu{
    _menu = menu;
    self.iconImageView.image = menu.icon;
    self.titleLabel.text = menu.title;
}
- (CGSize)sizeThatFits:(CGSize)size{
    return [self.flowlayout sizeThatFits:size resizeItems:YES];
}
- (void)layoutSubviews{
    [super layoutSubviews];
    CGRect bounds = self.bounds;
    self.flowlayout.bounds = bounds;
    [self.flowlayout layoutItemsWithResizeItems:YES];
}
@end
